package com.car.rental.vehicle.service.impl;

import com.car.rental.vehicle.config.RabbitMQConfig;
import com.car.rental.vehicle.entity.Vehicle;
import com.car.rental.vehicle.service.VehicleMessageService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class VehicleMessageServiceImpl implements VehicleMessageService {

    private final RabbitTemplate rabbitTemplate;
    
    @Override
    public void sendStatusChangeMessage(Vehicle vehicle, String oldStatus) {
        Map<String, Object> message = new HashMap<>();
        message.put("vehicleId", vehicle.getId());
        message.put("oldStatus", oldStatus);
        message.put("newStatus", vehicle.getStatus());
        message.put("timestamp", System.currentTimeMillis());
        
        rabbitTemplate.convertAndSend(
            RabbitMQConfig.VEHICLE_STATUS_EXCHANGE,
            RabbitMQConfig.VEHICLE_STATUS_ROUTING_KEY,
            message
        );
    }
} 